package logic

import (
	"cart_srv/pb/cart"
	"context"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGoodsAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsAddLogic {
	return &GoodsAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GoodsAddLogic) GoodsAdd(req *types.GoodsAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	add, err := l.svcCtx.CartSrv.GoodsAdd(l.ctx, &cart.AddGoodsRequest{
		GoodsTitle:  req.GoodsTitle,
		GoodsPrice:  float32(req.GoodsPrice),
		GoodsCover:  req.GoodsCover,
		GoodsStock:  req.GoodsStock,
		GoodsStatus: req.GoodsStatus,
		Checked:     req.GoodsStatus,
	})
	if err != nil {
		return &types.Response{
			Code: "500",
			Msg:  err.Error(),
			Data: nil,
		}, nil
	}

	return &types.Response{
		Code: "200",
		Msg:  "添加成功",
		Data: map[string]interface{}{
			"add": add,
		},
	}, nil
}
